import os
import subprocess
import sys

def check_dependencies():
    try:
        import flask
        return True
    except ImportError:
        return False

def install_dependencies():
    print("正在安装Flask...")
    subprocess.check_call([sys.executable, "-m", "pip", "install", "flask"])

def main():
    if not check_dependencies():
        install_dependencies()
    
    # 设置环境变量
    os.environ["FLASK_APP"] = "app.py"
    os.environ["FLASK_ENV"] = "development"
    
    # 使用python命令直接运行
    print("启动Flask开发服务器...")
    subprocess.Popen([sys.executable, "-m", "flask", "run", "--host=0.0.0.0", "--port=5000"])

if __name__ == "__main__":
    main()